package com.example.common;

/**
 * 基于ThreadLocal的工具类
 * 用于保存当前用户的id
 */
public class BaseContext {
    //ThreadLocal叫做线程变量，意思是ThreadLocal中填充的变量属于当前线程，该变量对其他线程而言是隔离的
    private static ThreadLocal<Long> threadLocal = new ThreadLocal();


    public static void setCurrentId(Long id){
        threadLocal.set(id);
    }

    public static Long getCurrentId(){
        return threadLocal.get();
    }
}
